﻿#include "widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    m_node = new QRemoteObjectNode(this);
    m_node->connectToNode(QUrl("local:myrpc"));

    m_rpc = m_node->acquireDynamic("MyRPC");

    connect(m_rpc,&QRemoteObjectDynamicReplica::initialized,this,&Widget::connectedRPC);
    connect(m_rpc,&QRemoteObjectDynamicReplica::stateChanged,[](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState) {
        qDebug() << "state change" << state << oldState;
    });
}

void Widget::connectedRPC()
{
    qDebug() << "dynamic connected";
    connect(m_rpc,SIGNAL(msgFromServer(QString)),this,SLOT(onMessageFromServer(QString)));
}

void Widget::onMessageFromServer(const QString &msg)
{
    qDebug() << "i'm dynamic form" << msg;
}

Widget::~Widget()
{
}
